#ifndef LOGIN_H
#define LOGIN_H

#include <QDialog>
#include <QApplication>
#include <QtNetwork/QTcpSocket>
#include "mainwindow.h"
#include <QTimer>

namespace Ui {
class login;
}

class login : public QDialog
{
    Q_OBJECT

public:
    explicit login(QWidget *parent = nullptr);
    ~login();

    QTcpSocket *socket ;
    QString name;

    QString ip_addr = "3w4z340113.wicp.vip";
    int port = 35785;

    // 重连定时器
    QTimer *timer_reConn;
    // 初始化连接定时器
    QTimer *timer_initConn;

    int connect_flag;

    int connfd;  //用户在服务器端的socket套接字文件描述符

public:
    void initfun();

signals:
    void send_socket(int connfd, QTcpSocket *socket, QString name, QString addr, int por);

private slots:
    void on_pushButton_regist_clicked();

    void on_pushButton_ent_clicked();

    /*读取服务器数据*/
    void readyRead();

    /*初始化链接服务器，2秒一次*/
    void init_Connect();

    /*断线重连，5秒一次*/
    void dis_ReConnect();

    /*断线检测*/
    void isDisConnection();

private:
    Ui::login *ui;

    MainWindow *w = new MainWindow();  //初始化mainwindow窗口

};

#endif // LOGIN_H
